package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.player.UserSign;
import com.yanqu.road.pb.sign.SignProto;
import com.yanqu.road.utils.date.DateHelper;

import java.util.Date;


public class SignPb {

	public static SignProto.SignDataMsg.Builder parseSignDataMsg(UserSign userSign, int cycleDays) {
		if(null == userSign){
			return null;
		}
		SignProto.SignDataMsg.Builder msg = SignProto.SignDataMsg.newBuilder();
		int signDays = userSign.getSignDays();
		if (DateHelper.isToday(new Date(userSign.getSignTime() * 1000))) {
			if(signDays > cycleDays){
				signDays = signDays % cycleDays;
			}
			msg.setCurrentSignDays(signDays);
			msg.setLastSignDays(signDays);
		} else {
			if(signDays >= cycleDays){
				signDays = signDays % cycleDays;
			}
			msg.setCurrentSignDays(signDays + 1);
			msg.setLastSignDays(signDays);
		}
		msg.setTotalSignDays(userSign.getTotalSignDays());
		return msg;
	}
}
